package com.yc.fileParse.xml;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ParseXml {
	
	public void syncXml() {
		String location = System.getProperty("sync.xml");
		//解析xml
		Element ele = null;
		try {
			ele = getRoot("F:\\git-my\\jdemo\\src\\main\\resources\\sync.xml");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Element dbinfo = ele.element("db-info");
		System.out.println(">" + dbinfo.getName());
		System.out.println("dbtype=" + dbinfo.elements().get(0).attribute("dbtype").getValue());
		
		
//		// 枚举所有子节点
//		for (Iterator i = ele.elementIterator(); i.hasNext(); ) {
//			Element element = (Element) i.next();
//			System.out.println(">>>>>" + element.getName());
//			
//			// do something
//		}
	}
	
	//获取root节点
	private Element getRoot(String fileName) throws MalformedURLException, DocumentException {
		SAXReader reader = new SAXReader();
		Document document = reader.read(new File(fileName));
		return document.getRootElement();
	}
		

	public static void main(String[] args) {
		ParseXml px = new ParseXml();
		px.syncXml();

	}

}
